$title	Illustration of an MPSGE Data File 

$setglobal model gtap

*	Field counts include nesting assignments, but nesting 
*	assignment fields are not included in the field component
*	list.

set	line	/1*7/,
	field	/f1*f6/;

set	fc(line,field,fcomp,*)	Field components /

	2.f1.label."$prod"	"$prod:Y(g,r)$vom(g,r) [PI_Y(g,r)]"
	2.f1.arg.Y		'g,r'
	2.f1.exc.vom		"g,r"
	2.f1.fun.PI_Y		"g,r"

	2.f2.nest.s		"g",	
	2.f2.arg.esub		"g",

	2.f3.setid.i		"s",	
	2.f3.arg.esubd		"i",	

	2.f4.nest.va		"s",	
	2.f4.arg.esubva		"g",

	3.f1.label.o		"o:P(g,r)"
	3.f1.arg.P		"g,r"

	3.f2.label.q		"q:vom(g,r)"
	3.f2.arg.vom		"g,r"

	3.f3.label.a		"a:RA(r) [R_Y(g,r)]"
	3.f3.arg.RA		"r"
	3.f3.fun.R_Y		"g,r"

	3.f4.label.t		"t:rto(g,r)"
	3.f4.arg.rto		"g,r"

	4.f1.label.i		"i:P(i,r)"
	4.f1.arg.P		"i,r"

	4.f2.label.q		"q:vdfm(i,g,r) [VDFM_(i,g,r)]"
	4.f2.arg.vdfm		"i,g,r"
	4.f2.fun.VDFM_		"i,g,r"
	4.f3.label.P		"p:(1+rtfd0(i,g,r))"
	4.f4.setid.i		"i.tl:"
	4.f5.label.a		"a:RA(r)"
	4.f5.arg.RA		"r"
	4.f6.label.t		"t:rtfd(i,g,r)"
	4.f6.arg.rtfd		"i,g,r"

	5.f1.label.i		"i:PM(i,r)"
	5.f1.arg.PM		"i,r"

	5.f2.label.q		"q:vifm(i,g,r) [VIFM_(i,g,r)]"
	5.f2.arg.vifm		"i,g,r"
	5.f2.fun.VIFM_		"i,g,r"

	5.f3.label.P		"p:(1+rtfi0(i,g,r))"

	5.f4.setid.i		"i.tl:"

	5.f5.label.a		"a:RA(r)"
	5.f5.arg.RA		"r"

	5.f6.label.t		"t:rtfi(i,g,r)"
	5.f6.arg.rtfi		"i,g,r"

	6.f1.label.i		"i:PS(sf,g,r)"
	6.f1.arg.PS		"sf,g,r"

	6.f2.label.q		"q:vfm(sf,g,r) [VSFM_(sf,g,r)]"
	6.f2.arg.vfm		"sf,g,r"
	6.f2.fun.VSFM_		"sf,g,r"

	6.f3.label.p		"p:(1+rtf0(sf,g,r))"

	6.f4.nest.va		"va:"

	6.f5.label.a		"a:RA(r)"
	6.f5.arg.RA		"r"

	6.f6.label.t		"t:rtf(sf,g,r)"
	6.f6.arg.rtf		"sf,g,r"

	7.f1.label.i		"i:PF(mf,r)"
	7.f1.arg.PF		"mf,r"
	7.f2.label.q		"q:vfm(mf,g,r) [VMFM_(mf,g,r)]"
	7.f2.arg.vfm		"mf,g,r"
	7.f2.fun.VSFM_		"mf,g,r"

	7.f3.label.p		"p:(1+rtf0(mf,g,r))"

	7.f4.nest.va		"va:"

	7.f5.label.a		"a:RA(r)"
	7.f5.arg.RA		"r"

	7.f6.label.t		"t:rtf(mf,g,r)"
	7.f6.arg.rtf		"mf,g,r"/;

set	fd(line,field,fcomp,*)	Field domains /

	2.f1.arg.(g,r)	
	2.f1.exc.(g,r)	
	2.f1.fun.(g,r)	
	2.f2.arg.(g)	
	2.f3.setid.(s)	
	2.f3.arg.(i)	
	2.f4.arg.(g)	

	3.f1.arg.(g,r)	
	3.f2.arg.(g,r)	
	3.f3.arg.(r)	
	3.f3.fun.(g,r)	
	3.f4.arg.(g,r)	

	4.f1.arg.(i,r)	 
	4.f2.arg.(i,g,r) 
	4.f2.fun.(i,g,r) 
	4.f5.arg.(r)	 
	4.f6.arg.(i,g,r) 

	5.f1.arg.(i,r)	 
	5.f2.arg.(i,g,r) 
	5.f2.fun.(i,g,r) 
	5.f5.arg.(r)	 
	5.f6.arg.(i,g,r) 

	6.f1.arg.(sf,g,r)	
	6.f2.fun.(sf,g,r)	
	6.f5.arg.(r)		
	6.f6.arg.(sf,g,r)	

	7.f1.arg.(mf,r)		
	7.f2.arg.(mf,g,r)	
	7.f2.fun.(mf,g,r)	
	7.f5.arg.(r)		
	7.f6.arg.(mf,g,r)/;

set	ft(line,field,fcomp)	Field text (constants or inputs in parens) /
	4.f3.arg	"(1+rtfd0(i,g,r))"
	5.f3.arg	"(1+rtfi0(i,g,r))"
	6.f3.arg	"(1+rtf0(sf,g,r))"
	7.f3.arg	"(1+rtf0(mf,g,r))" /

$exit

*	========================================================================================

*	Profit function for production and consumption activities:

* $prod:Y(g,r)$vom(g,r)	s:esub(g)    i.tl:esubd(i)  va:esubva(g)
* 	o:P(g,r)	q:vom(g,r)	a:RA(r)  t:rto(g,r)
* 	i:P(i,r)	q:vdfm(i,g,r)	p:(1+rtfd0(i,g,r)) i.tl:  a:RA(r) t:rtfd(i,g,r)
* 	i:PM(i,r)	q:vifm(i,g,r)	p:(1+rtfi0(i,g,r)) i.tl:  a:RA(r) t:rtfi(i,g,r)
* 	i:PS(sf,g,r)	q:vfm(sf,g,r)	p:(1+rtf0(sf,g,r))  va:   a:RA(r) t:rtf(sf,g,r)
* 	i:PF(mf,r)	q:vfm(mf,g,r)	p:(1+rtf0(mf,g,r))  va:   a:RA(r) t:rtf(mf,g,r)


*	Benchmark value shares:

parameter	thetaf(f,g,r)	Factor share of value added,
		thetad(i,g,r)	Domestic share of intermediate input,
		thetai(i,g,r)	Import share of intermediate input,
		theta_f(g,r)	Value added share of sectoral output;

thetaf(f,g,r) = 1;
thetaf(f,g,r)$sum(ff,vfm(ff,g,r)*(1+rtf0(ff,g,r)))
	= vfm(f,g,r)*(1+rtf0(f,g,r)) / sum(ff,vfm(ff,g,r)*(1+rtf0(ff,g,r)));

thetad(i,g,r) = 1;
thetad(i,g,r)$(vdfm(i,g,r)*(1+rtfd0(i,g,r)) + vifm(i,g,r)*(1+rtfi0(i,g,r)))
	= vdfm(i,g,r)*(1+rtfd0(i,g,r)) / 
		 (vdfm(i,g,r)*(1+rtfd0(i,g,r)) + vifm(i,g,r)*(1+rtfi0(i,g,r)));
thetai(i,g,r) = 1;
thetai(i,g,r)$vom(g,r)
	= (vdfm(i,g,r)*(1+rtfd0(i,g,r)) + vifm(i,g,r)*(1+rtfi0(i,g,r))) / vom(g,r);

theta_f(g,r) = 1;
theta_f(g,r)$vom(g,r) = sum(ff,vfm(ff,g,r)*(1+rtf0(ff,g,r))) / vom(g,r);

*	User cost indices for factors, domestic and imported
*	intermediate inputs:

$macro P_PF(f,g,r) (((PF(f,r)$mf(f)+PS(f,g,r)$sf(f))*(1+rtf(f,g,r)) \
		/ (1+rtf0(f,g,r)))$thetaf(f,g,r)  + 1$(thetaf(f,g,r) = 0))
$macro P_D(i,g,r)  ((P(i,r)*(1+rtfd(i,g,r)) \
		/ (1+rtfd0(i,g,r)))$thetad(i,g,r) + 1$(thetad(i,g,r)=0))
$macro P_I(i,g,r)  ((PM(i,r)*(1+rtfi(i,g,r)) \
		/ (1+rtfi0(i,g,r)))$(1-thetad(i,g,r)) + 1$(thetad(i,g,r)=1))

*	Compensated cost functions:


$if defined f_ $abort "The CF(g,r) macro requires a uniquely defined alias for f."
alias (f,f_);
$macro CF(g,r) ( \ 
	(sum(f_, thetaf(f_,g,r)*P_PF(f_,g,r)))$Leontief(esubva(g)) + \
	(prod(f_, P_PF(f_,g,r)**thetaf(f_,g,r)))$CobbDouglas(esubva(g)) + \
	(sum(f_, thetaf(f_,g,r)*P_PF(f_,g,r)**(1-esubva(g)))**(1/(1-esubva(g))))$CES(esubva(g)))

$macro CI(i,g,r) ( \
	(thetad(i,g,r)*P_D(i,g,r) + (1-thetad(i,g,r))*P_I(i,g,r))$Leontief(esubd(i)) + \
	(P_D(i,g,r)**thetad(i,g,r) * P_I(i,g,r)**(1-thetad(i,g,r)))$CobbDouglas(esubd(i)) + \
	( (thetad(i,g,r) *P_D(i,g,r)**(1-esubd(i)) + \
	(1-thetad(i,g,r))*P_I(i,g,r)**(1-esubd(i)))**(1/(1-esubd(i))))$CES(esubd(i)))

*	Cost function:

$if defined i_ $abort "The CY(g,r) macro requires a uniquely defined alias for i."
alias (i,i_);
$macro CY(g,r) ( \
  ( sum(i_, thetai(i_,g,r)*CI(i_,g,r)) + theta_f(g,r)*CF(g,r))$Leontief(esub(g)) + \
  (prod(i_, CI(i_,g,r)**thetai(i_,g,r))*CF(g,r)**theta_f(g,r))$CobbDouglas(esub(g)) + \
  ((sum(i_, thetai(i_,g,r)*CI(i_,g,r)**(1-esub(g))) + \
            theta_f(g,r)*CF(g,r)**(1-esub(g)))**(1/(1-esub(g))))$CES(esub(g)) )

prf_y(g,r)$vom(g,r)..		CY(g,r) =e= P(g,r) * (1-rto(g,r));

*	Demand functions:

$macro DDFM(i,g,r) (vdfm(i,g,r) * Y(g,r) * \
			(CY(g,r)/CI(i,g,r))**esub(g) * \
			(CI(i,g,r)/P_D(i,g,r))**esubd(i))$vdfm(i,g,r)
$macro DIFM(i,g,r) (vifm(i,g,r) * Y(g,r) * \
			(CY(g,r)/CI(i,g,r))**esub(g) * \
			(CI(i,g,r)/P_I(i,g,r))**esubd(i))$vifm(i,g,r)
$macro DFM(f,g,r)  (vfm(f,g,r)  * Y(g,r) * \
			(CY(g,r)/CF(g,r))**esub(g) * \
			(CF(g,r)/P_PF(f,g,r))**esubva(g))$vfm(f,g,r)

